package com.pm.controller.dept;

import com.pm.common.Response;
import com.pm.common.annotation.CurrentUser;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.dept.DepartmentCountySummary;
import com.pm.entity.po.security.User;
import com.pm.service.dept.DepartmentCountySummaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: pm_info_api
 * @description: 区县排名得分总汇
 * @author: xzj
 * @create: 2020-08-27 10:19
 **/
@Api(tags = "区县排名得分总汇")
@UserLoginToken
@RestController
@RequestMapping("/departmentCountySummary")
public class DepartmentCountySummaryController {

    @Autowired
    DepartmentCountySummaryService departmentCountySummaryService;

    @ApiOperation("新增接口")
    @PostMapping("/add")
    @ResponseBody
    @MyLog(value = "新增区县排名得分总汇")
    public Response<Integer> add(@RequestBody DepartmentCountySummary departmentCountySummary, @CurrentUser User user) {
        Response<Integer> response = null;
        departmentCountySummary.setAddUser(user.getUserId());
        departmentCountySummary.setEditUser(user.getUserId());
        Integer result = departmentCountySummaryService.add(departmentCountySummary);
        if (result > 0) {
            response = new Response<>(ExpCodeState.add_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.add_data_failed);
        }
        return response;
    }

    @ApiOperation("更新接口")
    @PostMapping("/update")
    @ResponseBody
    @MyLog(value = "更新区县排名得分总汇")
    public Response<Integer> update(@RequestBody DepartmentCountySummary departmentCountySummary, @CurrentUser User user) {
        Response<Integer> response = null;
        departmentCountySummary.setEditUser(user.getUserId());
        Integer result = departmentCountySummaryService.update(departmentCountySummary);
        if (result > 0) {
            response = new Response<>(ExpCodeState.update_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.update_data_failed);
        }
        return response;
    }

    @ApiOperation("单个对象查询接口")
    @PostMapping("/load")
    @ResponseBody
    public Response<DepartmentCountySummary> load(DepartmentCountySummary departmentCountySummary) {
        Response<DepartmentCountySummary> response = null;
        DepartmentCountySummary result = departmentCountySummaryService.load(departmentCountySummary);
        response = new Response<DepartmentCountySummary>(ExpCodeState.query_data_success, result);
        return response;
    }

    @ApiOperation("全部列表查询接口")
    @PostMapping("/getList")
    @ResponseBody
    public Response<List<DepartmentCountySummary>> getList(@RequestBody DepartmentCountySummary departmentCountySummary) {
        List<DepartmentCountySummary> result = departmentCountySummaryService.getList(departmentCountySummary);
        Response<List<DepartmentCountySummary>> res = new Response<List<DepartmentCountySummary>>(ExpCodeState.query_data_success, result);
        return res;
    }

    @ApiOperation("删除接口")
    @PostMapping("/remove")
    @ResponseBody
    @MyLog(value = "删除指标完成度信息")
    public Response<Integer> remove(DepartmentCountySummary departmentCountySummary) {
        Response<Integer> response = null;
        Integer result = departmentCountySummaryService.remove(departmentCountySummary);
        if (result > 0) {
            response = new Response<>(ExpCodeState.remove_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.remove_data_failed);
        }
        return response;
    }
}
